package net.zoneland.data.dataprofiling.common.domain;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Entity
@Table(name = "zz_dictEntity")
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(exclude = {"id"})
public class DictEntity {
    //编号
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    //标签名
    @Column(nullable = false,length = 100)
    private String name;
    //数据值
    @Column(nullable = false,length = 100)
    private String value;
    //类型
    @Column(nullable = false,length = 100)
    private String type;
    //描述
    private String description;
    //排序（升序）
    @Column
    private BigDecimal sort;
    //创建者
    private Integer createBy;
    //创建时间
    private Date createDate;
    //更新者
    private Long updateBy;
    //更新时间
    private Date updateDate;
    //备注信息
    @Column(length = 255)
    private String remarks;
    //删除标记
    private String delFlag;

    //    //父级编号
//    @Column(name = "parent_id")
//    private Long parentId;
    //父字典
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "pid")
    private DictEntity parentDictEntity;

    //子字典
    @OneToMany(targetEntity = DictEntity.class, cascade = { CascadeType.ALL }, mappedBy = "parentDictEntity")
    @Fetch(FetchMode.SUBSELECT)
    @OrderBy("sort")
    private List<DictEntity> childDicts = new ArrayList<>();

}
